import dash
from dash import html, dcc
from dash.dependencies import Input, Output
import plotly.express as px
import pandas as pd

csv_file = "data.csv"
csv_file = "hz_rt.csv"
csv_file = "hz_gen.csv"
# 读取CSV数据
df = pd.read_csv(csv_file)

# 创建Dash应用
app = dash.Dash(__name__)

# 定义布局
app.layout = html.Div(
    [
        html.H1("选择显示的数据"),
        dcc.RadioItems(
            id="column-selector",
            options=[
                {"label": "rate", "value": "rate"},
                {"label": "min", "value": "min"},
                {"label": "max", "value": "max"},
                {"label": "std_dev", "value": "std_dev"},
                {"label": "accum_dev", "value": "accum_dev"},
            ],
            value="rate",
        ),
        dcc.Graph(
            id="line-chart",
            style={"height": "600px"},
        ),
    ]
)


# 定义回调函数
@app.callback(Output("line-chart", "figure"), Input("column-selector", "value"))
def update_chart(selected_column):
    fig = px.line(df, x="time", y=selected_column, color="topic")
    return fig


if __name__ == "__main__":
    app.run(debug=True, port=8090)
